home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / toadboot.zip / TIMEBOOT.ASM < prev    next >
Assembly Source File  |  1991-05-21  |  3KB  |  128 lines

  1. ;Timeboot : TSR to reboot after n minutes after installation
  2. ;(where n can be 1..9).
  3. ;Given to the public domain
  4. ;David Kirschbaum
  5. ;Toad Hall
  6. ;kirsch@usasoc.soc.mil
  7.  
  8. CR    EQU    0DH
  9. LF    EQU    0AH
  10. JMP_FAR    EQU    0EAH
  11.  
  12. PAGE_0    SEGMENT    AT 0
  13.     ORG    472H
  14. Boot_Flag    dw    ?        ;Warm boot flag
  15. PAGE_0    ENDS
  16.  
  17. CSEG    SEGMENT PUBLIC PARA 'Code'
  18.     ASSUME    CS:CSEG,DS:CSEG
  19.     org    0
  20. BeginCode    equ    $
  21.  
  22.     org    80H
  23. cmdlen    label    byte
  24.     org    82H
  25. cmdparm    label    byte            ;nr of seconds
  26.     org    100H            ;.COM program
  27.  
  28. TimeBoot PROC    NEAR
  29.     jmp    Start            ;skip over runtime code
  30.  
  31. ticks    dw    0            ;delay in timer ticks
  32.  
  33. TimeBoot ENDP
  34.  
  35. ;Our new clock interrupt
  36. NewInt1C    PROC    FAR
  37.     ASSUME    DS:NOTHING
  38.  
  39.     cmp    CS:ticks,0        ;timed out?
  40.     jz    Timed_Out        ;yep, it's Party Time!
  41.      dec    CS:ticks        ;count down
  42. ;     jmp    CS:oldInt1C        ;'Well-behaved' programming
  43.                     ;vs. 'feelthy code'
  44.     db    JMP_FAR            ;JMP FAR instruction
  45. oldInt1C    LABEL    DWORD
  46. ofs_Int1C    dw    0
  47. seg_Int1C    dw    0
  48.  
  49. Timed_Out:
  50.     xor    ax,ax            ;Page 0
  51.     mov    DS,ax            ;point DS to memory base
  52.     ASSUME    DS:PAGE_0
  53.  
  54.     mov    Boot_Flag,1234H        ;flag DOS to warm boot
  55. ;    jmp    CS:Restart        ;go reboot
  56.     db    JMP_FAR            ;JMP FAR instruction
  57. Restart  LABEL    DWORD
  58. ;according to REBOOT.ASM, reboot IP and CS should be this:
  59. ;    dw    0E05BH            ; IP for reboot
  60. ;    dw    0F000H            ; CS for reboot
  61. ;according to WARMBOOT.COM's disassembly, it should be this:
  62.     dw    0000H            ; IP for reboot
  63.     dw    0FFFFH            ; CS for reboot
  64.  
  65. NewInt1C    ENDP
  66. EndCode    equ    $            ;last of TSR code
  67.  
  68.     ASSUME    DS:CSEG
  69. Start    PROC    NEAR
  70.  
  71.     call    GetTime            ;get timeout in minutes from cmdline
  72.                     ;(may die)
  73.     mov    cx,1092    ;60*18.2    ;one minute in timer ticks
  74.     xor    dx,dx            ;insure DX clear
  75.     mul    cx            ;AX = timer ticks
  76.     mov    ticks,ax        ;save the timeout value locally
  77.  
  78.     mov    ax,351CH        ;get Int 1CH timer int vector
  79.     int    21H
  80.     mov    ofs_Int1C,bx        ;save offset
  81.     mov    seg_Int1C,ES        ;and segment
  82.  
  83.     mov    dx,offset NewInt1C    ;our new interrupt service
  84.     mov    ax,251CH        ;set new 1CH timer int vector
  85.     int    21H
  86.     mov    dx,offset installed$    ;'TimeBoot installed ...'
  87.     mov    ah,9            ;display msg
  88.     int    21H
  89.  
  90. ;compute amount of memory to retain when going TSR (in paras)
  91.  
  92.     mov     dx,(EndCode-BeginCode+0Fh) SHR 4    ;memory to retain
  93.     mov    ah,31H            ;go TSR
  94.     int    21H
  95.  
  96. Start    ENDP
  97.  
  98. GetTime    PROC    NEAR
  99.     cmp    cmdlen,2        ;should be 2 char cmdline
  100.     jnz    Usage            ;nope, tell the dummy how
  101.     mov    al,cmdparm        ;get the nr of minutes
  102.     cmp    al,'1'            ;check for 1..9 minutes
  103.     jb    Usage
  104.     cmp    al,'9'
  105.     ja    Usage
  106.      mov    delay,al        ;stuff in msg
  107.      sub    al,'0'            ;deasciify
  108.      xor    ah,ah            ;clear msb
  109.      ret                ;return with minutes in AL
  110.  
  111. Usage:    mov    dx,offset usage$    ;How to
  112.     mov    ah,9            ;display msg
  113.     int    21H
  114.     mov    ax,4C01H        ;terminate, ERRORLEVEL 1
  115.     int    21H
  116. GetTime    ENDP
  117.  
  118. usage$    db    'TIMEBOOT v1.0 (Toad Hall)',CR,LF
  119.     db    'Usage:  TIMEBOOT n',CR,LF
  120.     db    'Where n is the number of minutes delay before a warm boot.'
  121.     db    CR,LF,'$'
  122.  
  123. installed$ db    'TIMEBOOT installed for '
  124. delay    db    'n minutes delay.',CR,LF,'$'
  125.  
  126. CSEG    ENDS
  127.     END    TimeBoot
  128.